<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="财务单号" prop="orderNo">
        <el-input v-model="form.orderNo" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="form.customerName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="orderStatus">
        <el-select v-model="form.orderStatus" filterable clearable>
          <el-option
            v-for="item in dict.type.ims_receipt_matters_status"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="orderNo" label="财务单号" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateRow(1,scope.row)">{{ scope.row.orderNo }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="reOrderType" label="收款事项" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ims_receipt_matters_type" :value="scope.row.reOrderType"/>
        </template>
      </el-table-column>
      <el-table-column prop="reOrderNo" label="关联单号" align="center"/>
      <el-table-column prop="reviewUserName" label="业务员" align="center"/>
      <el-table-column prop="customerName" label="所属客户" align="center"/>
      <el-table-column prop="incomes" label="应收金额(元)" align="center"/>
      <el-table-column prop="recvIncomes" label="已收金额(元)" align="center"/>
      <el-table-column prop="orderStatus" label="状态" align="center" width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ims_receipt_matters_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="销售时间" align="center" width="150"/>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="updateRow(2,scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
    <updateDialog ref="updateDialog" @ok="handleQuery"></updateDialog>
  </div>
</template>

<script>
import updateDialog from "./updateDialog";
import {changePayType, listPayList} from "../../../../api/payMng";
import {listUnit} from "../../../../api/imsMng";

export default {
  dicts: ['ims_receipt_matters_status', 'ims_receipt_matters_type'],
  name: 'PayList',
  components: {updateDialog},
  data() {
    return {
      loading: false,
      list: [],
      form: {
        orderNo: "",
        customerName: "",
        orderStatus: "",
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    changeStatus(row) {
      let req = {id: row.id, enable: row.enable}
      changePayType(req).then(res => {
        this.$message.success('操作成功')
      })
    },
    getList() {
      this.loading = false
      listPayList(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    },
    updateRow(flag, row) {
      this.$refs.updateDialog.show(flag, row)
    }
  }
}
</script>
